import { httpClient } from '@/utils/http/axios';
import { ErrorMessageMode } from '#/axios';
import { RoleOutputDtoSimple } from '@/api/identity/admin/role/model';
import { FunctionOutputDtoSimple } from '@/api/authorization/admin/function/model';
import { PageRequest, PageData } from '@/utils/common/types';

/** 管理-角色功能枚举 */
export enum Api {
  /** 读取角色 */
  ReadRoles = '/api/admin/roleFunction/readRoles',
  /** 读取角色功能 */
  ReadFunctions = '/api/admin/roleFunction/readFunctions',
}

//#region 读取角色信息
/**
 * 读取角色信息
 * @param request 分页请求
 * @param mode 错误消息模型
 */
export function readRoles(request: PageRequest, mode: ErrorMessageMode = 'message') {
  return httpClient.post<PageData<RoleOutputDtoSimple>>(
    {
      url: Api.ReadRoles,
      params: request,
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion
//#region 读取角色功能信息
/**
 * 读取角色功能信息
 * @param roleId 角色ID
 * @param request 分页请求
 * @param mode 错误消息模型
 */
export function readRoleFunctions(
  roleId: string | bigint,
  request: PageRequest,
  mode: ErrorMessageMode = 'message',
) {
  return httpClient.post<PageData<FunctionOutputDtoSimple>>(
    {
      url: `${Api.ReadFunctions}?roleId=${roleId}`,
      params: request,
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion
